OPC Studio User's Guide and Reference
Getting Started under new .NET using IDE
Client and Subscriber Development > Getting Started > Getting Started under .NET Framework or .NET > Getting Started under new .NET using IDE
In This Topic

In this Getting Started, we will create a console application running in .NET 6, 7 or 8 that will read a value from an OPC server, and display the value on the console.

Prerequisites

If you want to verify the version of .NET on your computer, use the dotnet --info command in the command prompt, and look for the Version field under ".NET runtimes installed:" in the generated output. Do not use dotnet --version, because this command only returns the version of the .NET command-line tools.

Console Application to Read Value from OPC Unified Architecture Server

  1. Start the IDE (Integrated Development Environment) of your choice.

  2. In this step, we will create a new .NET console application project.

    If you are using Visual Studio, select File -> New -> Project from the menu. In the New Project dialog, select Console App. Press the OK button.

    If you are using JetBrains Rider, select New Solution on the Welcome to JetBrains Rider screen. In the New Solution dialog, select Console Application. Verify the Language or change it to C#. Press the Create button.

  3. In this step, we will add a reference to the OpcLabs.QuickOpc NuGet package.

    If you are using Visual Studio, switch to the Solution Explorer window, right-click on the project node (ConsoleAppn), and select Manage NuGet Packages... command. In the NuGet: project window, switch to the Browse tab, and type OpcLabs.QuickOpc into the search box. Select the OpcLabs.QuickOpc package in the package list in the left pane of the window. In the right pane of the window, verify or change the package version next to the Version label. The version should be "Latest stable 5.80.build" (where build is a build number). Press the Install button.

    If you are using JetBrains Rider, switch to the NuGet window; if it is not visible, use View -> Tool Windows -> NuGet (Alt+7) command from the menu. In the NuGet window, switch to the Packages tab, and type OpcLabs.QuickOpc into the search box. Select the OpcLabs.QuickOpc package under Available Packages list in the left pane of the window. In the right pane of the window, verify or change the package version next to the Version label. The version should be "5.80.build" (where build is a build number). Press the green + button next to the name of your project. Press the Yes button when asked to confirm the installation of the package.

  4. Open the Program.cs file, and add following code to the beginning of the file:

    using OpcLabs.EasyOpc.UA;
    
  5. In Program.cs, replace the body of the Main method by following code:

    var client = new EasyUAClient();
    object value = client.ReadValue(
        "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer",
        "nsu=http://test.org/UA/Data/;i=10853");
    Console.WriteLine(value);
    Console.ReadLine();
    

    The program may now look like this in the IDE:

  6. If you are using Visual Studio, select Debug -> Start Debugging (F5) from the menu, or press the corresponding button on the toolbar.   

    If you are using JetBrains Rider, select Run -> Debug 'Default' (F5), or press the corresponding button on the toolbar. When the Edit configuration dialog appears, press the Debug button.

    This will build and launch the program. The value will be read from the OPC server and displayed on the console. Press Enter to exit the program.

Console Application to Read Value from OPC XML-DA Server

  1. Start the IDE (Integrated Development Environment) of your choice.

  2. In this step, we will create a new .NET console application project.

    If you are using Visual Studio, select File -> New -> Project from the menu. In the New Project dialog, select Console App. Press the OK button.

    If you are using JetBrains Rider, select New Solution on the Welcome to JetBrains Rider screen. In the New Solution dialog, select .NET Core -> Console Application. Verify the Language or change it to C#. Press the Create button.

  3. In this step, we will add a reference to the OpcLabs.QuickOpc NuGet package.

    If you are using Visual Studio, switch to the Solution Explorer window, right-click on the project node (ConsoleAppn), and select Manage NuGet Packages... command. In the NuGet: project window, switch to the Browse tab, and type OpcLabs.QuickOpc into the search box. Select the OpcLabs.QuickOpc package in the package list in the left pane of the window. In the right pane of the window, verify or change the package version next to the Version label. The version should be "Latest stable 5.80.build" (where build is a build number). Press the Install button.

    If you are using JetBrains Rider, switch to the NuGet window; if it is not visible, use View -> Tool Windows -> NuGet (Alt+7) command from the menu. In the NuGet window, switch to the Packages tab, and type OpcLabs.QuickOpc into the search box. Select the OpcLabs.QuickOpc package under Available Packages list in the left pane of the window. In the right pane of the window, verify or change the package version next to the Version label. The version should be "5.80.build" (where build is a build number). Press the green + button next to the name of your project. Press the Yes button when asked to confirm the installation of the package.

  4. Open the Program.cs file, and add following code to the beginning of the file:

    using OpcLabs.EasyOpc.DataAccess;
    
  5. In Program.cs, replace the body of the Main method by following code:

    var client = new EasyDAClient();
    object value = client.ReadItemValue(
        "http://opcxml.demo-this.com/XmlDaSampleServer/Service.asmx",
        "Dynamic/Analog Types/Double");
    Console.WriteLine(value);
    
  6. If you are using Visual Studio, select Debug -> Start Debugging (F5) from the menu, or press the corresponding button on the toolbar.   

    If you are using JetBrains Rider, select Run -> Debug 'Default' (F5), or press the corresponding button on the toolbar. When the Edit configuration dialog appears, press the Debug button.

    This will build and launch the program. The value will be read from the OPC server and displayed on the console. Press Enter to exit the program.

See Also